<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Http\Response;

class CustomException extends Exception
{
    protected $code;
    protected $msg = '';
    protected $args = [];

    public function __construct($code, $data = '')
    {
        $this->code = $code;
        if (is_array($data)) {
            $this->args = $data;
        } elseif (is_string($data)) {
            $this->msg = $data;
        }
    }

    public function resp()
    {
        return response(output('', $this->code, $this->msg, $this->args))->withException($this);
    }
}
